/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};

/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {

/******/ 		// Check if module is in cache
/******/ 		if(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;

/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};

/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;

/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}


/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;

/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;

/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "";

/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	'use strict';

	var _boneTime = __webpack_require__(2);

	var _boneTime2 = _interopRequireDefault(_boneTime);

	var _com = __webpack_require__(1);

	var _com2 = _interopRequireDefault(_com);

	var _urly = __webpack_require__(3);

	var _urly2 = _interopRequireDefault(_urly);

	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

	var components = (0, _com2.default)(['HeaderLayout', 'HeaderDock', 'LayoutMain', 'LayoutBox', 'LayoutSideMenu', 'TabsSide', 'TabsItemSide', 'Icon', 'List', 'ListItem', 'Product', 'ShoppingDock', 'GridRow', 'GridCol', 'MenuSquare']);

	Vue.filter('cut', function (value) {
		return value.substr(0, 30) + ' ...';
	});

	//cvxf
	new Vue({
		el: '#app',
		components: components,
		data: function data() {
			return {
				data: [],
				week: [],
				today: 1,
				tabs: [],
				currentDate: '',
				currentWeekDay: '',
				request: null,
				total: TOTAL,
				types: {
					1: '早餐',
					2: '中餐',
					3: '晚餐'
				},
				has: {
					breakfast: false,
					lunch: true,
					dinner: true
				}
			};
		},

		ready: function ready() {
			var url = new _urly2.default(window.location.href);

			var ddd = new Date(DATE[0]);
			this.today = ddd.getDay();
			if (url.getParams().today) {

				this.today = url.getParams().today;
			}
			var today = new Date();
			var weekday = today.getDay(); //星期几
			var date = today.getDate(); //日
			var haha = ['一', '二', '三', '四', '五', '六', '日'];
			if (weekday == 0) {
				weekday = 7;
			}

			//判断某天是否在要显示的日期内
			/*
	  function isIn(keyday){
	  	var flag = false;
	  	for(var i=0; i<DATE.length; i++){
	  		var day = DATE[i].split('-');
	  		var year1 = keyday.getFullYear();
	  		var mon1 = keyday.getMonth()+1;
	  		var day1 = keyday.getDate();
	  			var year2 = parseInt(day[0]);
	  		var mon2 = parseInt(day[1]);
	  		var day2 = parseInt(day[2]);
	  			if(year1==year2 && mon1==mon2 && day1==day2)
	  			flag = true;
	  	}
	  	return flag;
	  }*/

			for (var i = 0; i < DATE.length; i++) {
				var today2 = new Date();
				this.week.push(DATE[i]);

				var disable = false;
				//var tag = mon+'月'+today2.getDate()+'日';
				var bt = new _boneTime2.default(DATE[i] + ' 00:00:00');
				var tag = bt.format('MM月dd日');

				var current = false;
				if (i == 0) {
					current = true;
				}

				var dd  = bt.obj.getDay()>0?bt.obj.getDay()-1:6;

				this.tabs.push({
					id: i + 1,
					content: '周 ' + haha[dd],
					tag: tag,
					type: 'tag',
					current: current,
					disable: disable
				});
				if (current) {
					this.currentDate = DATE[0]; //today2.getFullYear()+'-'+mon+'-'+today2.getDate();
				}
			}

			/*
	  for (var i = 0; i<7; i++){
	  	var today2 = new Date();
	  		today2.setDate(date-weekday+1+i+7);
	  	var mon = today2.getMonth()+1;
	  		this.week.push(today2.getFullYear()+'-'+mon+'-'+today2.getDate());
	  	//
	  	 if(!isIn(today2)){
	  		 	continue;
	  	 }
	  	//
	  			var current = false;
	  	if(this.today == today2.getDay()){
	  		current = true;
	  	}
	  	var disable = false;
	  	if(weekday > today2.getDay() && today2.getDay() != 0){
	  		disable = false;
	  	}
	  	var tag = mon+'月'+today2.getDate()+'日';
	  	//if(weekday == today2.getDay()){
	  		//tag = '今 天';
	  	//}
	  		this.tabs.push({
	  		id: i+1,
	  		content: '周' + ' '+ haha[i],
	  		tag: tag,
	  		type: 'tag',
	  		current: current,
	  		disable: disable
	  	});
	  		if(current){
	  		this.currentDate = today2.getFullYear()+'-'+mon+'-'+today2.getDate();
	  	}
	  }*/

			this.loading(1);
		},
		events: {
			'tab-item-click': function tabItemClick(msg) {
				this.changeDate(msg);
			}
		},
		methods: {
			goDetail: function goDetail(pro) {
				window.location.href = SITE_URL + '/home/get_productdetail/id/' + pro.data.id + '/date/' + this.currentDate + '?type=' + pro.data.type; //+ '?date=' + this.currentDate;
			},
			changeDate: function changeDate(weekday) {

				this.loading(weekday);
			},
			loading: function loading(weekDay) {

				if (this.request) {
					this.request.abort();
				}
				this.currentWeekDay = weekDay;
				var mylist = this.$refs.mylist;
				var _this = this;
				this.request = $.ajax({
					url: SITE_URL + '/home/get_products',
					data: {
						date: _this.week[weekDay - 1]
					},
					type: 'post',
					success: function success(data) {

						mylist.setData(data, 'id');

						for (var key in data) {
							if (data[key].type == 1) {
								_this.has.breakfast = true;
							}
							if (data[key].type == 2) {
								_this.has.lunch = true;
							}
							if (data[key].type == 3) {
								_this.has.dinner = true;
							}
						}

						_this.data = mylist.getData();
						_this.currentDate = _this.week[weekDay - 1];
					},
					error: function error() {
						//alert('网络错误，请重试');
					}
				});
			},
			buy: function buy(pra) {
				if (this.request) {
					this.request.abort();
				}

				var _this = this;
				var flag = pra.check.checked;
				//this.$broadcast('product-unbuy', '');

				if (flag == false) {
					//alert('数量不能为0，如果想移除商品请前往购物删除');
					pra.check.setChecked(true);
				} else {
					pra.check.setChecked(true);
					this.request = $.ajax({
						url: SITE_URL + '/shoppingcart/addtocart',
						data: {
							productid: pra.id,
							amount: 1,
							date: _this.currentDate,
							type: pra.data.type
						},
						type: 'post',
						success: function success(data) {

							if (data.code) {
								_this.total = data.data;
								_this.loading(_this.currentWeekDay);
							} else {
								pra.check.setChecked(false);
								dialog.init('友情提醒', data.msg).ok(function () {
									return true;
								});
							}
						},
						error: function error() {
							//alert('网络错误，请重试');
						}

					});
				}
			},
			gotoshp: function gotoshp() {
				window.location = SITE_URL + '/shoppingcart';
			}
		}
	});

/***/ },
/* 1 */
/***/ function(module, exports) {

	"use strict";

	Object.defineProperty(exports, "__esModule", {
		value: true
	});

	exports.default = function (components) {

		var res = {};
		for (var i = 0; i < components.length; i++) {
			res[components[i]] = Bone[components[i]];
		}
		return res;
	};

/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {

	(function() {
	  /**
	   * @param {str} yyyy-mm-dd | yyyy-m-d | yyyy-mm-dd hh:mm:ss
	   */
	  function Time(str) {
	    this.obj = null //原生JS DATE对象
	    this.year = 0
	    this.month = 0
	    this.date = 0
	    this.hour = 0
	    this.minute = 0
	    this.second = 0

	    this.init(str)
	  }

	  /**
	   * 初始化日期数据
	   * @param {String} str yyyy-mm-dd | yyyy-m-d | yyyy-mm-dd hh:mm:ss
	   *                     yyyy/mm/dd | yyyy/m/d | yyyy/mm/dd hh:mm:ss
	   */
	  Time.prototype.init = function(str) {

	    if(typeof str == 'string'){
	      var d = str.split(' ')
	      var d1 = d[0].split('-')

	      if (d1.length === 1) {
	        d1 = d[0].split('/')
	      }

	      this.year = parseInt(d1[0])
	      this.month = parseInt(d1[1])
	      this.date = parseInt(d1[2])

	      if (d[1]) {
	        var d2 = d[1].split(':')
	        this.hour = parseInt(d2[0])
	        this.minute = parseInt(d2[1])
	        this.second = parseInt(d2[2])
	      }

	      this.obj = new Date(this.year, this.month - 1, this.date, this.hour, this.minute, this.second)
	    } else {
	      if(str instanceof Date){
	        this.obj = str
	      } else {
	        this.obj = new Date()
	      }
	      this.year = this.obj.getFullYear()
	      this.month = this.obj.getMonth()+1
	      this.date = this.obj.getDate()
	      this.hour = this.obj.getHours()
	      this.minute = this.obj.getMinutes()
	      this.second = this.obj.getSeconds()
	    }
	  }

	  /**
	   * 比较日期是否相等
	   * @param {Time} aim 对比的time对象
	   * @param {String} min 对比的最小精确单位
	   */
	  Time.prototype.equal = function(aim, min) {
	    var m = min || 'date'
	    var result = false

	    switch (m) {
	      case 'date':
	        {
	          if (this.year === aim.year && this.month === aim.month && this.date === aim.date) {
	            result = true
	            break
	          }
	        }
	      default:
	        {
	          result = false
	        }
	    }

	    return result

	  }

	  /**
	   * @param {format} yy-mm-dd hh:mm:ss
	   */
	  Time.prototype.format = function(format) {
	    function filter(num) {
	     return (Array(2).join('0') + num).slice(-2);
	    }

	    var result = format.replace('yyyy', this.year)
	    result = result.replace('MM', filter(this.month))
	    result = result.replace('dd', filter(this.date))
	    result = result.replace('HH', filter(this.hour))
	    result = result.replace('mm', filter(this.minute))
	    result = result.replace('ss', filter(this.second))

	    return result
	  }

	  Time.prototype.getTime = function() {
	    return this.obj.getTime()
	  }

	  /**
	   * 转换时间
	   * @param {param} Mon|Tues|..|Sun|+10days|-10days|2017year|9month|11date|11hour|11min|11seconds
	   * @return Time Object
	   */
	  Time.prototype.transfer = function(param){
	    var base = new Date(this.obj.getTime())
	    var d = {
	          day : base.getDay()==0?7:base.getDay(),
	          date : base.getDate(),
	          month : base.getMonth(),
	          year : base.getFullYear(),
	          date: base.getDate(),
	          hours: base.getHours(),
	          minutes: base.getMinutes(),
	          seconds: base.getSeconds()
	        },
	        driver = filter(param),
	        week = {
	          'Mon': 1,
	          'Tues': 2,
	          'Wed': 3,
	          'Thur': 4,
	          'Fri': 5,
	          'Sat': 6,
	          'Sun': 7
	        },
	        funcs = {
	          'year': 'setFullYear',
	          'month': 'setMonth',
	          'date': 'setDate',
	          'hours': 'setHours',
	          'minutes': 'setMinutes',
	          'seconds': 'setSeconds'
	        }

	    switch(driver.mode){
	      case 'Mon': case 'Tues': case 'Wed': case 'Thur': case 'Fri': case 'Sat': {
	        base.setDate(d.date - d.day + week[driver.mode])
	        return new Time(base)
	        break;
	      }
	      case 'Sun': {
	        base.setDate(d.date + (7-d.day))
	        return new Time(base)
	        break;
	      }
	      case 'days': {
	        base.setDate(d.date + driver.value)
	        return new Time(base)
	        break;
	      }
	      case 'year': case 'month': case 'date': case 'hours': case 'minutes': case 'seconds': {

	        if(driver.prefix === '+' || driver.prefix === '-'){

	          base[funcs[driver.mode]](d[driver.mode] + driver.value)
	        }  else {
	          base[funcs[driver.mode]](driver.value)
	        }

	        return new Time(base)
	        break;
	      }
	      default:{
	        return this
	      }
	    }

	    function filter(str){
	      var prefix = str.match(/^\+|\-/),
	          mode = str.match(/[a-zA-Z]+/)

	      return {
	        prefix: prefix?prefix[0]:'',
	        mode: mode?mode[0]:'',
	        value: parseInt(str)
	      }
	    }

	    return this
	  }


	  if (true) {
	    module.exports = Time
	  } else {
	    window.bonetime = Time
	  }

	})()


/***/ },
/* 3 */
/***/ function(module, exports) {

	'use strict';

	var urly = function urly(href) {
		this.href = '';
		this.href2 = '';
		this.paramsString = '';
		this.params = {};

		this.setHref = function () {};

		this.getHref = function () {
			return this.href;
		};

		this.setParams = function (params) {
			for (key in params) {
				//if(this.params[key] != undefined){
				if (key != '' && key != undefined && params[key] != '' && params[key] != undefined) this.params[key] = params[key];
				if (this.params[key] != undefined && params[key] == '' || params[key] == undefined) delete this.params[key];
			}
			var p = '';
			var i = 0;
			for (key in this.params) {
				if (key != '' && key != undefined) {
					if (i == 0) {
						p = p + key + '=' + this.params[key];
					} else {
						p = p + '&' + key + '=' + this.params[key];
					}
					i++;
				}
			}
			this.paramsString = p;
			this.href = this.href2 + '?' + this.paramsString;
		};

		this.init = function (href) {

			this.href = href;
			if (this.href.indexOf('?') >= 0) {
				this.paramsString = this.href.split('?')[1];
				this.href2 = this.href.split('?')[0];
			} else {
				this.href2 = href;
			}
			this.parseParams();
		};

		//return array
		this.parseParams = function () {
			var par = this.paramsString.split('&');
			var size = par.length;

			while (size--) {
				//console.log(size);
				var p = par[size];
				//console.log(p)
				p = p.split('=');
				this.params[p[0]] = p[1] ? p[1] : '';
			}
		};

		this.getParams = function () {
			return this.params;
		};

		this.init(href);
	};

	module.exports = urly;

/***/ }
/******/ ]);
